<?php

/*------------------------------------------------
*
*   Explay Engine Content Management System.
*   Copyright © 2008 Golovdinov Alexander.
*
*-------------------------------------------------
*
*   Official site: wwww.alex-home.spb.ru/explay.html
*   Contact e-mail: golovdinov@gmail.com
*
*   GNU General Public License original source:
*   http://www.gnu.org/licenses/gpl-3.0.html
*
------------------------------------------------*/

if (!defined ('EXPLAY')) exit;

if (is_cached ('last_publish.php', 240)) $content = file_get_contents ($_SERVER['DOCUMENT_ROOT'].'/include/cache/last_publish.php');
else {
	$content = build_publish ();
	cache_file ('last_publish.php', $content);
}

$block = array ();
$block['header'] = $block_header;
$block['name'] = $block_name;
$block['content'] = $content;

Templater::set_var ('block', $block);

($align == 'left')
	? CORE::add_block (Templater::display ('block.tpl'), 'left')
	: CORE::add_block (Templater::display ('block.tpl'), 'right');


function build_publish () {
	global $db;
	
	$return = '';
	$get_last_arts = $db->query ("SELECT art_id, art_category, art_header, art_author, c.cat_header, u.user_name, u.user_login FROM ".DB_PEREFIX."_articles AS a
		LEFT JOIN (SELECT cat_name, cat_header FROM ".DB_PEREFIX."_art_category) AS c ON a.art_category = c.cat_name
		LEFT JOIN (SELECT user_id, user_name, user_login FROM ".DB_PEREFIX."_users) AS u ON a.art_author = u.user_id
		WHERE art_like_page = 'no' AND art_visible = 'on' ORDER BY art_id DESC LIMIT 0, 12");
	
	$return .= '<div id="last_publish">';
	while (list ($id, $cat, $header, $author, $cheader, $uname, $ulogin) = $db->fetch_row ($get_last_arts)) {

		(!empty($cat))
			? $categ = "<a href=\"/articles/$cat/\" class=\"cat\">$cheader</a> / "
			: $categ = "";

		$return .= "\n<img src=\"/images/user.gif\" style=\"margin-right:5px;\" alt=\"\" /><a href=\"/users/$ulogin\" class=\"user\">$uname</a> &rarr; ".
		"{$categ}<a href=\"/articles/$id.html\" class=\"header\">$header</a><br />";
	}
	$return .= '</div><p align="right">&raquo; <a href="/art_comments/">эфир комментариев</a></p>';
	return $return;
}
